//
//  FingerPrintController.swift
//  Monosaccharides
//
//  Created by iSolar on 2017/11/15.
//  Copyright © 2017年 nothing. All rights reserved.
//

import UIKit
import SVProgressHUD

class FingerPrintController: BaseViewController {

    var swfitFingerPrint : UIButton!
    
    var ocFingerPrint : UIButton!
    
    var lockPassButton: UIButton!
    
    var cameraButton : UIButton!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        self.title = "指纹解锁"
        
        swfitFingerPrint = UIButton.init(frame: CGRect.init(x: (KWidth - 100 ) / 2, y: 100, width: 100, height: 35))
        ocFingerPrint = UIButton.init(frame: CGRect.init(x: (KWidth - 100 ) / 2, y: 160, width: 100, height: 35))
        lockPassButton = UIButton.init(frame: CGRect.init(x: (KWidth - 100 ) / 2, y: 220, width: 100, height: 35))
        cameraButton = UIButton.init(frame: CGRect.init(x: (KWidth - 100 ) / 2, y: 280, width: 100, height: 35))
        
        view.addSubview(swfitFingerPrint)
        view.addSubview(ocFingerPrint)
        view.addSubview(lockPassButton)
        view.addSubview(cameraButton)
        
        swfitFingerPrint.tag = 10
        ocFingerPrint.tag = 11
        lockPassButton.tag = 12
        cameraButton.tag = 13
        
        swfitFingerPrint.setTitle("swift指纹解锁", for: .normal)
        ocFingerPrint.setTitle("oc指纹解锁", for: .normal)
        lockPassButton.setTitle("手势解锁", for: .normal)
        cameraButton.setTitle("系统相册", for: .normal)
        
        swfitFingerPrint.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        ocFingerPrint.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        lockPassButton.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        cameraButton.titleLabel?.font = UIFont.systemFont(ofSize: 15)
        
        swfitFingerPrint.setTitleColor(UIColor.black, for: .normal)
        ocFingerPrint.setTitleColor(UIColor.black, for: .normal)
        lockPassButton.setTitleColor(UIColor.black, for: .normal)
        cameraButton.setTitleColor(UIColor.black, for: .normal)
        
        ocFingerPrint.addTarget(self, action: #selector(fingerPrintAction(_:)), for: .touchUpInside)
        swfitFingerPrint.addTarget(self, action: #selector(fingerPrintAction(_:)), for: .touchUpInside)
        lockPassButton.addTarget(self, action: #selector(fingerPrintAction(_:)), for: .touchUpInside)
        cameraButton.addTarget(self, action: #selector(fingerPrintAction(_:)), for: .touchUpInside)
        
        
    }
    
    
    @objc func fingerPrintAction(_ sender: UIButton) {
        
        print("----------\(sender.tag)------------")
        
        switch sender.tag {
        case 10:
            
            FingerPrintHelper.fingerPrintPWDResult(withMsg: "使用你的设备指纹解锁", block: { (result :FingerPrintHelper.FPCheck) in
                switch result {
                case .success:
                    SVProgressHUD.showSuccess(withStatus: "用户解锁成功")
                case .failed:
                    SVProgressHUD.showError(withStatus: "用户解锁失败")
                case .pwdNotSet:
                    SVProgressHUD.showError(withStatus: "未设置密码")
                case .touchIDNotSet:
                    SVProgressHUD.showError(withStatus: "未设置指纹")
                case .notAvailable:
                    SVProgressHUD.showError(withStatus: "系统不支持")
                }
            })
            
            break
        case 11:
            
            let vc = FingerPassViewController()
            navigationController?.pushViewController(vc, animated: true)
            
            break
        case 12:
            
            let vc = GestureViewController ()
            navigationController?.pushViewController(vc, animated: true)
            
            break
        case 13:
            
            let vc = CameraViewController()
            navigationController?.pushViewController(vc, animated: true)
            
            break
            
        default:
            break
        }
        
    }
    
    
}
